package com.bsh.controller.user;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.bsh.api.params.DtoBankInfo;
import com.bsh.dto.UserEditDto;
import com.bsh.dto.UserListQryDto;
import com.bsh.service.BankService;
import com.bsh.service.UserService;
import com.bsh.utils.Pager;
import com.mysql.jdbc.StringUtils;

@Controller
public class UserBankController {
	private static Logger log = LoggerFactory.getLogger(UserBankController.class);

	@Autowired
	HttpServletRequest request;
	@Autowired
	HttpServletResponse response;
	@Autowired
	UserService userService;
	@Autowired
	BankService bankServ;

	/**
	 * 用户银行卡列表
	 */
	@RequestMapping(value = "/user/bank/list")
	public ModelAndView login(@ModelAttribute UserListQryDto dto) {
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/pages/user/userBankList");
		
		String pageStr = request.getParameter("pageIndex");
		Integer pageIndex = Integer.parseInt(StringUtils.isNullOrEmpty(pageStr) ? "1" : pageStr);

		String sizeStr = request.getParameter("pageSize");
		Integer pageSize = Integer.parseInt(StringUtils.isNullOrEmpty(sizeStr) ? "10" : sizeStr);

		Pager pager = new Pager(pageIndex, pageSize);
		List<Map<String, Object>> list = userService.getBankPage(pager,dto);
		mv.addObject("list", list);
		mv.addObject("pager", pager);
		mv.addObject("dto", dto==null?new UserEditDto():dto);
		
		List<DtoBankInfo> bankList = bankServ.queryBankList();
		mv.addObject("bankList", bankList);
		
		return mv;
	}
}
